    
// изменяет цвет фона элементов, если чтавим чекбокс, что это скрытое сообщение
function HiddenClick()
{
    var objPrivate, color, color2, objFilesCounter, files_counter;
    objPrivate = document.getElementById("HIDDEN");
    if (objPrivate.checked) 
    {
        color_backgroud = "#F1F8F5"; 
        color_checkbox = "#3CB97D"; 
    }
    else 
    {
        color_backgroud = "";
        color_checkbox = "";
    }
    //document.getElementById("FUA_ID").style.backgroundColor = color_backgroud;
    if (document.getElementById("MESSAGE"))
        document.getElementById("MESSAGE").style.backgroundColor = color_backgroud;
    
    //document.getElementById("TASK_TIME").style.backgroundColor = color_backgroud;
    objFilesCounter = document.getElementById("lastfile");
    files_counter = parseInt(objFilesCounter.value);
    for (i=1; i<=files_counter; i++)
    {
        document.getElementById("file_"+i+"_").style.backgroundColor = color_backgroud;
    }
    if (document.getElementById("CATEGORY_ID"))
        document.getElementById("CATEGORY_ID").style.backgroundColor = color_backgroud;

    if (document.getElementById("PROJECT_ID"))
        document.getElementById("PROJECT_ID").style.backgroundColor = color_backgroud;
    
    if (document.getElementById("STATUS_ID"))
        document.getElementById("STATUS_ID").style.backgroundColor = color_backgroud;
    
    if (document.getElementById("DIFFICULTY_ID"))    
        document.getElementById("DIFFICULTY_ID").style.backgroundColor = color_backgroud;
    
    if (document.getElementById("RESPONSIBLE_USER_ID"))
        document.getElementById("RESPONSIBLE_USER_ID").style.backgroundColor = color_backgroud;
    
    if (document.getElementById("CRITICALITY_ID"))    
        document.getElementById("CRITICALITY_ID").style.backgroundColor = color_backgroud;
    
    if (document.getElementById("MARK_ID"))    
        document.getElementById("MARK_ID").style.backgroundColor = color_backgroud;

    if (document.getElementById("PROJECT_ID"))    
        document.getElementById("PROJECT_ID").style.backgroundColor = color_backgroud;
    
    objPrivate.style.backgroundColor = color_checkbox;
}

// вставка цитаты в ответ
function SupQuoteMessage(id)
{
    var selection;
    if (document.getSelection)
    {
        selection = document.getSelection().toString();
        selection = selection.replace(/\r\n\r\n/gi, "_newstringhere_");
        selection = selection.replace(/\r\n/gi, " ");
        selection = selection.replace(/  /gi, "");
        selection = selection.replace(/_newstringhere_/gi, "\r\n\r\n");
    }
    else
    {
        selection = document.selection.createRange().text;
    }
    if (selection!="")
    {
        document.form1.MESSAGE.value += "<QUOTE>"+selection+"</QUOTE>\n";
    }
}


// вставка спец. тэгов
var QUOTE_open = 0;
var CODE_open = 0;
var B_open = 0;
var I_open = 0;
var U_open = 0;
var QUOTE_title = "Цитата (alt+q)";
var CODE_title = "Код (alt+c)";
var B_title = "B";
var I_title = "I";
var U_title = "U";

var myAgent   = navigator.userAgent.toLowerCase();
var myVersion = parseInt(navigator.appVersion);
var myVersion = parseInt(navigator.appVersion);
var is_ie  = ((myAgent.indexOf("msie") != -1)  && (myAgent.indexOf("opera") == -1));
var is_nav = ((myAgent.indexOf('mozilla')!=-1) && (myAgent.indexOf('spoofer')==-1)
 && (myAgent.indexOf('compatible') == -1) && (myAgent.indexOf('opera')==-1)
 && (myAgent.indexOf('webtv')==-1) && (myAgent.indexOf('hotjava')==-1));

var is_win = ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1));
var is_mac = (myAgent.indexOf("mac")!=-1);

function insert_tag(thetag, objTextarea)
{
    var tagOpen = eval(thetag + "_open");
    if (tagOpen == 0)
    {
        if (DoInsert(objTextarea, "<"+thetag+">", "</"+thetag+">"))
        {
            eval(thetag + "_open = 1");
            eval("document.form1." + thetag + ".value += '*'");
        }
    }
    else
    {
        DoInsert(objTextarea, "</"+thetag+">", "");
        eval("document.form1." + thetag + ".value = ' " + eval(thetag + "_title") + " '");
        eval(thetag + "_open = 0");
    }
}

function mozillaWr(textarea, open, close)
{
    var selLength = textarea.textLength;
    var selStart = textarea.selectionStart;
    var selEnd = textarea.selectionEnd;

    if (selEnd == 1 || selEnd == 2)
    selEnd = selLength;

    var s1 = (textarea.value).substring(0,selStart);
    var s2 = (textarea.value).substring(selStart, selEnd)
    var s3 = (textarea.value).substring(selEnd, selLength);
    textarea.value = s1 + open + s2 + close + s3;

    textarea.selectionEnd = 0;
    textarea.selectionStart = selEnd + open.length + close.length;
    return;
}

function DoInsert(objTextarea, Tag, closeTag)
{
    var isOpen = false;

    if ( myVersion >= 4 && is_ie && is_win && objTextarea.isTextEdit)
    {
        objTextarea.focus();
        var sel = document.selection;
        var rng = sel.createRange();
        rng.colapse;
        if ((sel.type=="Text" || sel.type=="None") && rng != null)
        {
            if (closeTag!="")
            {
                if (rng.text.length > 0) 
                    Tag += rng.text + closeTag; 
                else
                    isOpen = true;
            }
            rng.text = Tag;
        }
    }
    else
    {
        if (is_nav && document.getElementById)
        {
            if (closeTag!="" && objTextarea.selectionEnd > objTextarea.selectionStart)
            {
                mozillaWr(objTextarea, Tag, closeTag);
                isOpen = false;
            }
            else
            {
                mozillaWr(objTextarea, Tag, '');
                isOpen = true;
            }
        }
        else
        {
            objTextarea.value += Tag;
            isOpen = true;
        }
    }
    objTextarea.focus();
    return isOpen;
}

function addNewRow(el)
{    
    var checkid = "file_"+document.getElementById('lastfile').value+"_"
    if (el.id == checkid)
    {
        //if (el.id==document.getElementById('lastfile').textContent )
        var nHTML = "";
        var div = document.getElementById('fileslist');
        var sHTML=div.innerHTML;
        var p = sHTML.length;
        var s = sHTML.lastIndexOf('file_',p);
        if(s<0)return false;
        var e = sHTML.lastIndexOf('_"',p);
        if(e<0)return false;
        var n = parseInt(sHTML.substr(s+5,e-s));
        var newid = 'file_'+(++n)+'_';
        nHTML = nHTML+'<input type="file" onchange="addNewRow(this)" name="'+newid+'" id="'+newid+'" /><br />';
        var newDiv = document.createElement('div');
        newDiv.innerHTML = nHTML;
        document.getElementById('fileslist').appendChild(newDiv);
        document.getElementById('lastfile').value = n;
        //document.getElementById('fileslist').innerHTML += nHTML;
        
    }
}

function SetResponsible(select_name)
{
    var obResponsible = document.getElementById("RESPONSIBLE_USER_ID");
    if (!obResponsible.disabled)
    {
        var obSelect = document.getElementById(select_name);
        var iValue, iResponsible, mess, i;
        if (obSelect)
        {
            iValue = obSelect[obSelect.selectedIndex].value;
            if (arCategory_RESP[iValue]) 
                iResponsible = arCategory_RESP[iValue];
            mess = 'Для выбранной категории ответственный сотрудник по умолчанию не определен.';
            if (parseInt(iResponsible)>0)
            {
                for(i=0; i<obResponsible.options.length; i++)
                    if (obResponsible.options[i].value==iResponsible) 
                        obResponsible.selectedIndex = i;
            }
            else alert(mess);
        }
    }
}
